home *** CD-ROM | disk | FTP | other *** search
- /* Search.c */
-
- // File contains all search routines for Cycle database
-
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <clib/asl_protos.h>
- #include <clib/dos_protos.h>
- #include <clib/exec_protos.h>
- #include <clib/intuition_protos.h>
- #include <clib/gadtools_protos.h>
- #include <clib/graphics_protos.h>
- #include <graphics/gfxmacros.h>
- #include <graphics/GfxBase.h>
- #include <intuition/intuition.h>
- #include <intuition/IntuitionBase.h>
- #include <libraries/asl.h>
- #include <libraries/dos.h>
- #include <libraries/gadtools.h>
- #include <string.h>
- #include <stdlib.h>
- #include <stdio.h>
-
- #include "ResultsWindow.c"
- //#include "Search.h"
-
- struct TagItem frtags[] =
- {
- ASLFR_TitleText, (ULONG)"CycleDataBase File Requester",
- ASLFR_InitialHeight, MYHEIGHT,
- ASLFR_InitialWidth, MYWIDTH,
- ASLFR_InitialLeftEdge, MYLEFTEDGE,
- ASLFR_InitialTopEdge, MYTOPEDGE,
- ASLFR_PositiveText, (ULONG)"Okay",
- ASLFR_NegativeText, (ULONG)"Cancel",
- ASLFR_InitialFile, (ULONG)".cdb",
- TAG_DONE
- };
-
- /*
- ** Function for loading the database from a file.
- */
- // Code removed for copyright reasons
-
- // Function creates gadgets in search window
- struct Gadget *createSearchGadgets(struct Gadget **glistptr, void *searchvi,
- UWORD searchtopborder, struct Gadget *search_gads[], struct StringInfo *gad_ptr[])
- {
- struct NewGadget ng;
- struct Gadget *gad;
-
- STRPTR names[] =
- {
- "Destination",
- "Date",
- NULL,
- };
-
- /* All the gadget creation calls accept a pointer to the previous gadget, and
- ** link the new gadget to that gadget's NextGadget field. Also, they exit
- ** gracefully, returning NULL, if any previous gadget was NULL. This limits
- ** the amount of checking for failure that is needed. You only need to check
- ** before you tweak any gadget structure or use any of its fields, and finally
- ** once at the end, before you add the gadgets.
- */
-
- /* The following operation is required of any program that uses GadTools.
- ** It gives the toolkit a place to stuff context data.
- */
- gad = CreateContext(glistptr);
-
- /* Since the NewGadget structure is unmodified by any of the CreateGadget()
- ** calls, we need only change those fields which are different.
- */
-
- ng.ng_LeftEdge = 180;
- ng.ng_TopEdge = 10+searchtopborder;
- ng.ng_Width = 150;
- ng.ng_Height = 12;
- ng.ng_GadgetText = "_Enter Search String:";
- ng.ng_TextAttr = &Topaz80;
- ng.ng_VisualInfo = searchvi;
- ng.ng_GadgetID = MYGAD_SEARCHSTRING;
- ng.ng_Flags = NG_HIGHLABEL;
- search_gads[MYGAD_SEARCHSTRING] = gad = CreateGadget(STRING_KIND, gad, &ng,
- GTST_String, "",
- GTST_MaxChars, 100,
- GT_Underscore, '_',
- TAG_END);
- gad_ptr[0] = (struct StringInfo *) gad->SpecialInfo;
-
- ng.ng_LeftEdge = 450;
- ng.ng_GadgetText = NULL;
- ng.ng_GadgetID = MYGAD_DESTDATE;
- search_gads[MYGAD_DESTDATE] = gad = CreateGadget(MX_KIND, gad, &ng,
- GTMX_Active, 0,
- GTMX_Labels, names,
- GTMX_Spacing, 4,
- TAG_END);
-
- return(gad);
- }
-
- /*
- ** Function to handle a GADGETUP or GADGETDOWN event.
- */
- BOOL searchGadgetEvent(struct Screen *mysc, struct Window *searchwin, struct Gadget *gad, UWORD code,
- struct Gadget *search_gads[], struct StringInfo *gad_ptr[], BOOL &destdate)
- {
- long state = 0;
-
- switch (gad->GadgetID)
- {
- case MYGAD_SEARCHSTRING:
- return(TRUE);
- break;
- case MYGAD_DESTDATE:
- GT_GetGadgetAttrs(search_gads[MYGAD_DESTDATE], searchwin, NULL, GTMX_Active, &state, TAG_END);
- if(state == 0)
- destdate = FALSE;
- else if(state == 1)
- destdate = TRUE;
- break;
- }
- return(FALSE);
- }
-
- /*
- ** Function to handle vanilla keys.
- */
- void searchVanillaKey(struct Window *searchwin, UWORD code,
- struct Gadget *search_gads[])
- {
- switch (code)
- {
- case 'e':
- case 'E':
- ActivateGadget(search_gads[MYGAD_SEARCHSTRING], searchwin, NULL);
- break;
- }
- }
-
- /*
- ** Function for defining and displaying About Alert message.
- */
- void about_alert()
- {
- char message[161];
-
- strcpy(message, " Advanced Search program created by Donald W Millican.");
- strcat(message,
- " (C) Copyright 1999 DWM Productions.");
- strcat(message,
- " Version 1.0 26/09/99. Press Left Mouse Button to continue.");
-
- message[0]=0; /* X position of the first string */
- message[1]=32; /* - " - */
- message[2]=16; /* Y - " - */
-
- message[56]='\0'; /* NULL sign which finish of the first string. */
- message[57]=TRUE; /* Continuation byte set to TRUE (new string). */
-
- message[58]=0;
- message[59]=32;
- message[60]=32;
-
- message[96]='\0';
- message[97]=TRUE;
-
- message[98]=0; /* X position of the third string. */
- message[99]=32; /* - " - */
- message[100]=48; /* Y - " - */
-
- message[159]='\0'; /* NULL sign which finish of the third string. */
- message[160]=FALSE; /* Continuation byte set to FALSE (last string). */
-
- /* We will now display the Alert message: */
- DisplayAlert( RECOVERY_ALERT, message, 64 );
- }
-
- // Function to deal with user input
- void eventhandling(struct Screen *mysc, struct Window *searchwin,
- struct Gadget *search_gads[], struct Menu *mainmenustrip, struct StringInfo *gad_ptr[])
- {
- struct IntuiMessage *imsg;
- ULONG imsgClass;
- UWORD imsgCode;
- UWORD menu_number, which_menu, which_item;
- MenuItem *item;
- BOOL terminated = FALSE;
- BOOL destdate = FALSE;
- BOOL result = FALSE;
- struct Gadget *gad;
- int count = 0;
- char sentence[DESTLENGTH];
- UBYTE *data_entered;
- int position = 0;
-
- data_entered = (UBYTE *)sentence;
-
- // Load cycledbase file
- result = load(searchwin);
- if(result == 0)
- {
- terminated = TRUE;
- }
-
- while (!terminated)
- {
- Wait (1 << searchwin->UserPort->mp_SigBit);
-
- /* GT_GetIMsg() returns an IntuiMessage with more friendly information for
- ** complex gadget classes. Use it wherever you get IntuiMessages where
- ** using GadTools gadgets.
- */
-
- while ((!terminated) &&
- (imsg = GT_GetIMsg(searchwin->UserPort)))
- {
- /* Presuming a gadget, of course, but no harm...
- ** Only dereference this value (gad) where the Class specifies
- ** that it is a gadget event.
- */
- gad = (struct Gadget *)imsg->IAddress;
-
- imsgClass = imsg->Class;
- imsgCode = imsg->Code;
- menu_number = imsg->Code;
-
- /* Use the toolkit message-replying function here... */
- GT_ReplyIMsg(imsg);
-
- switch (imsgClass)
- {
- /* --- WARNING --- WARNING --- WARNING --- WARNING --- WARNING ---
- ** GadTools puts the gadget address into IAddress of IDCMP_MOUSEMOVE
- ** messages. This is NOT true for standard Intuition messages,
- ** but is an added feature of GadTools.
- */
- case IDCMP_VANILLAKEY:
- searchVanillaKey(searchwin, imsgCode, search_gads);
- break;
-
- case IDCMP_GADGETDOWN:
- case IDCMP_GADGETUP:
- // terminated should not be used here
- // we want the program to continue running
- // after something has been entered
- result = searchGadgetEvent(mysc, searchwin, gad, imsgCode, search_gads,
- gad_ptr, destdate);
- if(result == TRUE)
- {
- searchrecords.recs[0] = 0;
- // Copy out contents of string gadget
- strcpy(data_entered, gad_ptr[0]->Buffer);
-
- // Perform search
-
- // Code removed for copyright reasons
- }
- break;
-
- case IDCMP_MENUPICK:
- // Menu chosen
- which_menu=MENUNUM(menu_number);
- which_item=ITEMNUM(menu_number);
-
- while( menu_number != MENUNULL )
- {
- /* Get the address of the item: */
- item = (struct MenuItem *) ItemAddress( mainmenustrip, menu_number );
-
- /* Check which item was selected: */
- if( which_menu == 0 )
- {
- if( which_item == 0 )
- {
- // about selected
- about_alert();
- }
- if( which_item == 1 )
- {
- terminated = TRUE;
- }
- }
- /* Get the following item's menu number: */
- menu_number = item->NextSelect;
- }
- break;
-
- case IDCMP_CLOSEWINDOW:
- terminated = TRUE;
- break;
-
- case IDCMP_REFRESHWINDOW:
- /* With GadTools, the application must use GT_BeginRefresh()
- ** where it would normally have used BeginRefresh()
- */
- GT_BeginRefresh(searchwin);
- GT_EndRefresh(searchwin, TRUE);
- break;
- }
- }
- }
- }
-
- // Function to create and open search window
- void
- searchwindow()
- {
- struct Window *searchwin;
- struct TextFont *font;
- struct Screen *mysc;
- struct Gadget *searchglist, *search_gads[NO_GADS];
- struct StringInfo *gad_ptr[PTRS];
- void *searchvi;
- APTR searchvisualinfo;
- UWORD searchtopborder;
- struct Menu *mainmenustrip;
-
- /****************************/
- /* THE MENU STRUCTURE: */
- /****************************/
- struct NewMenu main_menu[] =
- {
- {NM_TITLE,"Main",0,0,0,0,},
- {NM_ITEM,"About","A",0,0,0,},
- {NM_ITEM,"Quit","Q",0,0,0,},
- {NM_END,NULL,0,0,0,0,},
- };
-
- // Copy file identification string to header structure
- strcpy(headerdata.file_id, FILEDEF);
- // Set number of actual records to zero
- records.recs[0] = 0;
-
- /* Open topaz 8 font, so we can be sure it's openable
- ** when we later set ng_TextAttr to &Topaz80:
- */
-
- if (NULL == (font = OpenFont(&Topaz80)))
- {
- EasyRequest(NULL, &nofont, NULL);
- }
- else
- {
- if (NULL == (mysc = LockPubScreen(NULL)))
- {
- EasyRequest(NULL, &noscreen, NULL);
- }
- else
- {
- if (NULL == (searchvi = GetVisualInfo(mysc, TAG_END)))
- {
- EasyRequest(NULL, &novisinfo, NULL);
- }
- else
- {
- /* Here is how we can figure out ahead of time how tall the */
- /* window's title bar will be: */
- searchtopborder = mysc->WBorTop + (mysc->Font->ta_YSize + 1);
-
- if (NULL == createSearchGadgets(&searchglist, searchvi, searchtopborder,
- search_gads, gad_ptr))
- {
- EasyRequest(NULL, &nogadgets, NULL);
- }
- else
- {
-
- if (NULL == (searchwin = OpenWindowTags(NULL,
- WA_Title, "Advanced Search",
- WA_Gadgets, searchglist, WA_AutoAdjust, TRUE,
- WA_Width, 490, WA_MinWidth, 490,
- WA_InnerHeight, 50, WA_MinHeight, 50,
- WA_DragBar, TRUE, WA_DepthGadget, TRUE,
- WA_Activate, TRUE, WA_CloseGadget, TRUE,
- WA_SimpleRefresh, TRUE, WA_NewLookMenus, TRUE,
- WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW | IDCMP_MENUPICK |
- IDCMP_VANILLAKEY | IDCMP_GADGETDOWN | STRINGIDCMP,
- WA_PubScreen, mysc,
- TAG_END)))
- {
- EasyRequest(NULL, &nowindow, NULL);
- }
- else
- {
- /* After window is open, gadgets must be refreshed with a
- ** call to the GadTools refresh window function.
- */
- GT_RefreshWindow(searchwin, NULL);
-
- searchvisualinfo=GetVisualInfo(mysc, TAG_END);
- mainmenustrip=CreateMenus(main_menu, TAG_END);
- LayoutMenus(mainmenustrip, searchvisualinfo, GTMN_NewLookMenus, TRUE, TAG_END);
- SetMenuStrip(searchwin, mainmenustrip);
-
- // Deal with interaction
- eventhandling(mysc, searchwin, search_gads, mainmenustrip, gad_ptr);
-
- ClearMenuStrip( searchwin );
- FreeMenus(mainmenustrip);
-
- CloseWindow(searchwin);
- }
- }
- /* FreeGadgets() even if createAllGadgets() fails, as some
- ** of the gadgets may have been created...If glist is NULL
- ** then FreeGadgets() will do nothing.
- */
- FreeGadgets(searchglist);
- FreeVisualInfo(searchvi);
- FreeVisualInfo(searchvisualinfo);
- }
- UnlockPubScreen(NULL, mysc);
- }
- CloseFont(font);
- }
- }
-
-